<template>
  <div>
    <div class="video-container">
      <div class="aside-buttom-comtainer">
        <div class="button-block" @click="drawer = !drawer">
          <i class="el-icon-notebook-2"></i>
          <span>章节</span>
        </div>
        <div class="button-block" @click="dialogTableVisible = true">
          <i class="el-icon-s-comment"></i>
          <span>评论</span>
        </div>
      </div>
      <div class="playerContainer">
        <danmu-player :sectionId="sectionId"></danmu-player>
      </div>
    </div>

    <div class="tabs-container">
      <div class="width-container tabs-width-container">
        <div
          @click="activeTagIndex = 0"
          :class="['tabs-block', { 'active-tab': activeTagIndex == 0 }]"
        >
          评论
        </div>
      </div>
    </div>

    <div class="main-container">
      <div class="width-container">
        <div class="course-comment-list-container">
          <div class="send-comment-wrap">
            <div>课程评价</div>
            <div class="send-comment-button" @click="dialogTableVisible = true">
              发布评论
            </div>
          </div>
          <el-card v-for="(item, index) in commentList" :key="index">
            <div class="comment-user-block">
              <img :src="item.userImg" alt="" />
              <div class="comment-user-name">{{ item.nickName }}</div>
            </div>
            <div class="comment-content">{{ item.comment }}</div>
            <div class="comment-time">
              时间：{{ item.cerateTime.split("T")[0] }}
            </div>
          </el-card>
        </div>
        <div class="adv-list-container">
          <el-card>
            <div slot="header" class="clearfix adv-title">推荐课程</div>
            <div class="adv-course-list">
              <div
                v-for="(item, index) in advList"
                :key="index"
                class="course-container"
                @click="
                  $myUtils.OpenNewWindow('/courseDetail', { id: item.id })
                "
              >
                <img :src="item.image" alt="" />
                <div class="course-info-block">
                  <div class="course-name">{{ item.courseName }}</div>
                  <div class="value-applay">
                    <span>￥{{ item.price }}</span>
                    <span>·</span>
                    <span>{{ item.level }}</span>
                    <span>·</span>
                    <span>{{ item.enroll }}</span>
                  </div>
                </div>
              </div>
            </div>
          </el-card>
        </div>
      </div>
    </div>

    <el-dialog
      title="我要评论"
      :visible.sync="dialogTableVisible"
      @close="
        dialogTableVisible = false;
        myComment = '';
      "
    >
      <el-input
        type="textarea"
        resize="none"
        :rows="4"
        placeholder="扯淡、吐槽、表扬、鼓励……想说啥就说啥！"
        v-model="myComment"
      >
      </el-input>
      <el-button @click="sendComment">发表评论</el-button>
    </el-dialog>

    <el-drawer
      title="课程章节"
      :visible.sync="drawer"
      direction="ltr"
      :modal="false"
      size="100%"
      :with-header="false"
    >
      <el-card v-for="(item, index) in courseChapter" :key="index">
        <div class="course-card-header">
          <div class="chapterTitle">{{ item.name }}</div>
        </div>
        <div class="section-container">
          <div
            v-for="(node, step) in item.sectionList"
            :key="step"
            class="section-block"
            @click="toVideo(node.id)"
          >
            <i class="el-icon-video-play"></i>
            <span>{{ `${item.id}-${step + 1} ${node.title}` }}</span>
          </div>
        </div>
      </el-card>
    </el-drawer>
  </div>
</template>
<script>
import {
  getCourseChapter,
  getVideoComment,
  toCommentVideo,
  getRecommendList,
} from "@/services/course";
import danmuPlayer from "./components/danmuPlayer.vue";

export default {
  components: {
    danmuPlayer,
  },
  data() {
    return {
      courseInfo: [],
      courseChapter: [],
      advList: [],
      activeTagIndex: 0,
      commentList: [],
      dialogTableVisible: false,
      myComment: "",
      drawer: false,
      sectionId: "",
      courseId: "",
    };
  },
  methods: {
    toGetCourseChapter(courseId) {
      getCourseChapter({ courseId: this.courseId }).then((res) => {
        this.courseChapter = res.data.data;
      });
    },
    getAdvList() {
      getRecommendList({ number: 8 }).then((res) => {
        this.advList = res.data.data;
      });
    },
    getCourseCommentList() {
      getVideoComment({ sectionId: this.sectionId }).then((res) => {
        this.commentList = res.data.data;
      });
    },
    sendComment() {
      toCommentVideo({
        sectionId: this.sectionId,
        comment: this.myComment,
      }).then((res) => {
        this.getCourseCommentList();
        this.myComment = "";
        this.dialogTableVisible = false;
      });
    },

    toVideo(sectionId) {
      if (this.$route.query.sectionId != sectionId) {
        this.$router.replace({
          path: "/videoDetail",
          query: { courseId: this.courseId, sectionId },
        });
      }
    },
    getId() {
      this.sectionId = this.$route.query.sectionId;
      this.courseId = this.$route.query.courseId;
    },
  },
  created() {
    this.getId();
    this.toGetCourseChapter();
    this.getAdvList();
    this.getCourseCommentList();
  },

  watch: {
    "$route.query.sectionId": function () {
      this.getId();
      // this.initVideoPlayer();
      // this.toGetCourseChapter();
      this.getAdvList();
      this.getCourseCommentList();
    },
  },
};
</script>
<style lang="scss" scoped>
.video-container {
  background: #1c1f21;
  display: flex;
  min-height: 522px;
  height: calc(100vh - 141px);
  .aside-buttom-comtainer {
    width: 60px;
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 9999;
    flex-shrink: 0;

    .button-block {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      margin: 20px 0 30px;
      cursor: pointer;
      i {
        font-size: 24px;
        color: rgba(255, 255, 255, 0.6);
        margin-bottom: 5px;
      }
      span {
        font-size: 12px;
        color: rgba(255, 255, 255, 0.4);
      }
      &:hover {
        i,
        span {
          color: white;
        }
      }
    }
  }
  .playerContainer {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    background-color: black;
  }
}

.tabs-container {
  height: 68px;
  line-height: 68px;
  background: #fff;
  box-shadow: 0 4px 8px 0 rgb(28 31 33 / 10%);
  .width-container.tabs-width-container {
    width: 1152px;
    margin: 0 auto;
    display: flex;
    justify-content: flex-start;
    .tabs-block {
      position: relative;
      color: #1c1f21;
      font-weight: bold;
      margin-right: 60px;
      margin-top: 15px;
      line-height: 37px;
      cursor: pointer;
    }
    .active-tab {
      &::after {
        content: "";
        display: block;
        width: 20px;
        border-radius: 2px;
        height: 3px;
        background: #f20d0d;
        margin: 0 auto;
      }
    }
  }
}

.main-container {
  margin-top: 20px;
  .width-container {
    display: flex;
    justify-content: space-between;
    .course-comment-list-container {
      flex: 1;
      .send-comment-wrap {
        display: flex;
        justify-content: space-between;
        margin-bottom: 20px;
        .send-comment-button {
          color: #545c63;
          background-color: rgba(84, 92, 99, 0.1);
          cursor: pointer;
          border-radius: 18px;
          padding: 7px 16px;
          font-size: 14px;
        }
      }
      ::v-deep .el-card {
        margin-bottom: 20px;
        .el-card__body {
          display: flex;
          padding-left: 10px;
          .comment-user-block {
            display: flex;
            flex-direction: column;
            align-items: center;
            margin-right: 20px;
            width: 80px;
            color: #787d82;
            font-size: 12px;

            img {
              width: 48px;
              height: 48px;
              margin-bottom: 10px;
            }
          }
          .comment-content {
            flex: 1;
            font-size: 14px;
            margin-top: 10px;
          }
          .comment-time {
            width: 120px;
            font-size: 12px;
            align-self: flex-end;
            color: #b5b9bc;
          }
        }
      }
    }
    .adv-list-container {
      width: 320px;
      padding-left: 32px;
      ::v-deep .el-card {
        background-color: transparent;
        border: 0;
        box-shadow: 0 0 0;
        .el-card__header {
          padding: 0;
          .adv-title {
            font-weight: 700;
            font-size: 14px;
            padding-bottom: 10px;
          }
        }
        .el-card__body {
          padding: 0;
          .adv-course-list {
            .course-container {
              display: flex;
              height: 67px;
              margin-bottom: 8px;
              justify-content: space-between;
              img {
                width: 80px;
                height: 60px;
                border-radius: 6px;
              }
              .course-info-block {
                display: flex;
                flex-direction: column;
                width: 224px;
                height: 67px;
                border-bottom: 1px solid rgba(43, 51, 59, 0.1);
                .course-name {
                  padding-top: 8px;
                  font-size: 14px;
                  height: 22px;
                  line-height: 22px;
                  margin-bottom: 4px;
                  cursor: pointer;
                  color: #545c63;
                  overflow: hidden;
                  /*文本不会换行*/
                  white-space: nowrap;
                  /*当文本溢出包含元素时，以省略号表示超出的文本*/
                  text-overflow: ellipsis;
                }
                .value-applay {
                  font-size: 12px;
                  color: #545c63;
                  display: flex;
                  span {
                    margin-right: 10px;
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

::v-deep .el-dialog {
  width: 560px;
  border-radius: 10px;
  margin: 0 !important;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  .el-dialog__header {
    font-size: 16px;
    font-weight: bold;
    color: #1c1f21;
  }
  .el-dialog__body {
    padding-top: 10px;
    padding-bottom: 20px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    .el-textarea {
      margin-bottom: 20px;
    }
    .el-button {
      background-color: $primary-color;
      color: white;
      border-radius: 20px;
    }
  }
}

.width-container {
  width: 1152px;
  margin: 0 auto;
}

::v-deep .el-drawer__wrapper {
  position: absolute;
  left: 60px;
  top: 73px;
  bottom: 68px;
  width: 350px;
  min-height: 522px;
  .el-drawer {
    box-shadow: 0 8px 16px 0 #1c1f21;
    background-color: #26292c;
    .el-drawer__body {
      overflow-y: auto;

      &::-webkit-scrollbar {
        display: none;
      }
      .el-card {
        box-shadow: 0 0 0;
        background-color: transparent;
        border: 0;
        color: white;
        .el-card__body {
          padding-bottom: 0;
          .chapterTitle {
            font-size: 14px;
            line-height: 24px;
            margin-bottom: 5px;
          }
          .section-container {
            .section-block {
              height: 28px;
              font-size: 12px;
              display: flex;
              justify-content: flex-start;
              align-items: center;
              cursor: pointer;
              i {
                font-size: 16px;
                color: rgba(255, 255, 255, 0.6);
                margin-right: 4px;
                margin-left: 12px;
              }
              span {
                color: rgba(255, 255, 255, 0.6);
              }
              &:hover {
                background: rgba(242, 13, 13, 0.05);
                color: #f20d0d;
                i,
                span {
                  color: #f20d0d;
                }
              }
            }
          }
        }
      }
    }
  }
}
</style>